package com.example.demo.zaqizabatest;

/**
 * @ClassName QueueArray
 * @Author lys4134
 * @Date 2021/12/24 20:53:33
 * @Description QueueArray
 * @Version 1.0
 **/
public class QueueArrayTest {

}

class QueueArray{
    private int maxSize;
    private int front;
    private int rear;
    private int[] queue;

    public QueueArray(int maxSize) {
        front = -1;
        rear = -1;
        queue = new int[maxSize];
        this.maxSize = maxSize;
    }

    public boolean isFull(){
        return rear == maxSize - 1;
    }

    public boolean isEmpty(){
        return rear == front;
    }

    public void addQueue(int value){
        if (isFull()){
            resize();
        }
        rear++;
        queue[rear] = value;
    }

    public int getQueue(){
        if (isEmpty()){
            throw new RuntimeException("队列为空");
        }
        front++;
        return queue[front];
    }

    public int showHead(){
        if (isEmpty()){
            throw new RuntimeException("队列为空");
        }
        return queue[front++];
    }

    public int showTail(){
        if (isEmpty()){
            throw new RuntimeException("队列为空");
        }
        return queue[rear];
    }

    public void showQueue(){
        if (isEmpty()){
            System.out.println("队列为空");
            return;
        }
        for (int i = 0; i < maxSize; i++){
            System.out.printf("array[%d]=%d\n", i, queue[i]);
        }
    }



    public void resize(){
        if (isFull()){

        }
    }
}

